package com.hyts.mvc.base.interceptor;

import com.google.common.collect.Lists;
import com.hyts.mvc.bean.web.MvcParamContext;
import com.hyts.mvc.model.HandlerWrapper;
import com.hyts.mvc.model.InterceptorWrapper;

import java.util.List;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.mvc.base.interceptor
 * author:Libo/Alex
 * create-date:2019-07-05 13:28
 * email:liboware@gmail.com
 * description:此类主要用于:
 */
public class WebMvcInterceptorAdapter extends WebMvcInterceptor{


    @Override
    public IntercepterResult before(MvcParamContext param) {
        System.out.println("before:"+param.get("ceshi"));
        return IntercepterResult.SUCCESS;
    }

    @Override
    public IntercepterResult after(MvcParamContext param) {
        System.out.println("after:"+param.get("ceshi"));
        return IntercepterResult.SUCCESS;
    }


    public static void main(String[] args){
        List<InterceptorWrapper> interceptorWrappers =
                Lists.newArrayList(InterceptorWrapper.builder().order(0).
                interceptor(new WebMvcInterceptorAdapter()).build(),InterceptorWrapper.builder().order(1).
                        interceptor(new WebMvcInterceptorAdapter()).build());
        WebMvcInterceptorStack interceptorStack = new WebMvcInterceptorStack(interceptorWrappers).build();
        MvcParamContext context = null;
        try {
            context = new MvcParamContext(null,null,
                    HandlerWrapper.builder().clazz(WebMvcAddTest.class).
                                    executeMethod(WebMvcAddTest.class.getMethod("test",null)).build());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        context.put("ceshi","12312");
        try {
            interceptorStack.execute(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}